{% extends 'shop/base.html' %}

{% block content %}
<div class="row">
    <div class="col-md-3">
        <div class="card mb-4">
            <div class="card-header">
                商品分类
            </div>
            <div class="list-group list-group-flush">
                <a href="{% url 'product-list' %}" class="list-group-item list-group-item-action {% if not category_slug %}active{% endif %}">全部商品</a>
                {% for c in categories %}
                <a href="{% url 'product-list-by-category' c.slug %}" class="list-group-item list-group-item-action {% if category.slug == c.slug %}active{% endif %}">{{ c.name }}</a>
                {% endfor %}
            </div>
        </div>
    </div>
    <div class="col-md-9">
        <div class="row">
            {% for product in products %}
            <div class="col-md-4 mb-4">
                <div class="card h-100">
                    <img src="{{ product.image.url }}" class="card-img-top" alt="{{ product.name }}">
                    <div class="card-body">
                        <h5 class="card-title">{{ product.name }}</h5>
                        <p class="card-text">¥{{ product.price }}</p>
                        <p class="card-text">库存: {{ product.stock }}</p>
                        <a href="{% url 'product-detail' product.id product.slug %}" class="btn btn-primary">查看详情</a>
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>
</div>
{% endblock %}